package br.org.etec.dotcao.model;

import javax.persistence.NoResultException;

import br.org.etec.dotcao.dao.UserDao;
import br.org.etec.dotcao.exception.InvalidCredentialException;


public class UserRepositoryImpl extends RepositoryImpl<User> implements UserRepository{

	public UserRepositoryImpl() {
		super(User.class);
	}

	@Override
	public User authenticate(String username, String password) throws InvalidCredentialException {
		UserDao dao = (UserDao) delegate;
		
		try {
			return dao.authenticate(username, password);
		} catch (NoResultException e) {
			throw new InvalidCredentialException();
		}
	}

	@Override
	public User authenticate(OauthInfo oauth) throws InvalidCredentialException {
		UserDao dao = (UserDao) delegate;
		
		try {
			return dao.authenticate(oauth);
		} catch (NoResultException e) {
			throw new InvalidCredentialException();
		}
	}

	@Override
	public User getByEmail(String email) {
		UserDao dao = (UserDao) delegate;
		
		return dao.getByEmail(email);
	}

}
